package org.larkdoc.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.larkdoc.dao.UserInfoMapper;
import org.larkdoc.model.entity.UserInfo;
import org.larkdoc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * 用户信息业务功能实现类
 * 
 * @author  zhangpeijun[zhangpeijun1024@qq.com]
 * @version  [v1.0.1, 2017年10月17日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    
    @Autowired
    UserInfoMapper userInfoMapper;
    
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userInfoMapper.deleteByPrimaryKey(id);
    }
    
    @Override
    public int insert(UserInfo record) {
        return userInfoMapper.insert(record);
    }
    
    @Override
    public int insertSelective(UserInfo record) {
        return userInfoMapper.insertSelective(record);
    }
    
    @Override
    public UserInfo selectByPrimaryKey(Integer id) {
        return userInfoMapper.selectByPrimaryKey(id);
    }
    
    @Override
    public int updateByPrimaryKeySelective(UserInfo record) {
        return userInfoMapper.updateByPrimaryKeySelective(record);
    }
    
    @Override
    public int updateByPrimaryKey(UserInfo record) {
        return userInfoMapper.updateByPrimaryKey(record);
    }
    
    @Override
    public UserInfo getByAccount(String account) {
        if (StringUtils.isNotBlank(account)) {
            return userInfoMapper.getByAccount(account);
        } else {
            return null;
        }
    }
    
    @Override
    public List<UserInfo> queryByNameOrAccount(String record) {
        if (StringUtils.isNotBlank(record)) {
            List<UserInfo> query = userInfoMapper.queryByNameOrAccount(record);
            // 屏蔽密码。
            if (CollectionUtils.isNotEmpty(query)) {
                for (UserInfo userInfo : query) {
                    userInfo.setPassword("");
                }
            }
            return query;
        } else {
            return null;
        }
    }
    
    @Override
    public List<UserInfo> queryByProjectId(Integer projectId) {
        if (projectId > 0) {
            return userInfoMapper.queryByProjectId(projectId);
        } else {
            return null;
        }
    }
    
    @Override
    public List<UserInfo> queryByProjectId(List<Integer> projectId) {
        if (CollectionUtils.isNotEmpty(projectId)) {
            return userInfoMapper.queryByProjectIds(projectId);
        } else {
            return null;
        }
    }
    
}
